package com.xjtu.platform.demander.submit.impl;


import com.xjtu.platform.answer.answer.QuestionDto;
import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.demander.submit.SubmitService;
import com.xjtu.platform.demander.submit.dao.SubmitDao;
import com.xjtu.platform.demander.submit.submitDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SubmitServiceImpl implements SubmitService {

    @Resource
    private SubmitDao submitDao;

    @Override
    public void setSubmit(submitDto dto) {
        submitDao.setSubmit(dto);
    }

    @Override
    public List<submitDto> getSubmitList(CurrentUser user) {
        String userId = user.getUserId();
        return submitDao.findSubmitById(userId);
    }

    @Override
    public Integer countSubmit(CurrentUser user) {
        String userId = user.getUserId();
        return submitDao.countSubmit(userId);
    }

    @Override
    public void deleteSubmit(submitDto dto) {
        submitDao.deleteSubmit(dto);
    }

    @Override
    public void insertQues(String request_id, String path, String question_id, Integer count) {
        QuestionDto questionDto = new QuestionDto();
        questionDto.setRequest_id(request_id);
        questionDto.setPath(path);
        questionDto.setQuestion_id(question_id);
        questionDto.setCount(count);
        submitDao.insertQues(questionDto);
    }

    @Override
    public void addStage(String path, Integer i) {
        submitDao.addStage(path,i+1);
    }

    @Override
    public int getStage(String path) {
        return submitDao.getStage(path);
    }

    @Override
    public submitDto searchByRequestId(String request_id) {
        return submitDao.searchByRequestId(request_id);
    }

}
